#include"progress.h"
#include<unistd.h>
#include<string.h>

#define NUM 101
#define CH '='

void process()
{
    char buff[NUM];
    memset(buff,0,sizeof(buff));
    const char* str="|/-\\";
    int len = strlen(str);
    int cnt =0;
    while(cnt<=100)
    {
        printf("[%-100s][%d%%][%c]\r",buff,cnt,str[cnt%len]);
        fflush(stdout);
        buff[cnt]=CH;
        usleep(30000);
        cnt++;
    }
    printf("\n");

}

void Process(double total, double current)
{
    char buff[NUM];
    memset(buff,0,sizeof(buff));
    const char* str = "|/-\\";
    int len = strlen(str);
    //当前进度
    int num = (int)(current*100)/total;
    int i=0;
    for(i=0;i<num;i++)
    {
        buff[i]=CH;
    }
    static int cnt = 0;
    cnt%=len;
    printf("[%-100s][%d%%][%c]\r",buff,num,str[cnt]);
    cnt++;
    fflush(stdout);
}

